<template>
    <div class="distributor">

        <div class="distributor-body" v-loading="loading">
            <h2>PODpartner Affiliate Program</h2>
            <div class="distributor-link">
                <h3>Unique affiliate link</h3>
                <strong v-text="url"></strong>
                <button @click="doCopy()"><svg-icon name="copy" /><span>Copy</span></button>
                <h6>
                    <svg-icon name="notify" />
                    <span>Referred customers should create a PODpartner account within 60 days from clicking on your affiliate link so that they can be associated with your efforts.</span>
                </h6>
            </div>

            <div class="distributor-statistics">

                <ul>
                    <li>
                        <h3><span>Referred new customer</span></h3>
                        <strong v-text="user_count"></strong>
                    </li>
                    <li>
                        <h3>
                            <span>Total order volume </span>
                            <!-- <el-tooltip placement="top">
                                <div slot="content">The total order volume includes all completed orders placed by <br> referred customers, excluding any cancelled or refunded orders.</div>
                                <svg-icon name="notify" />
                            </el-tooltip> -->

                            <UxPopper placement="top" :delay="0">
                                <svg-icon name="notify" />
                                <div slot="pop">The total order volume includes all completed orders placed by <br> referred customers, excluding any cancelled or refunded orders.</div>
                            </UxPopper>

                        </h3>
                        <strong v-text="total_count"></strong>
                    </li>
                    <li>
                        <h3>
                            <span>Total order amount</span>
                            <UxPopper placement="top" :delay="0">
                                <svg-icon name="notify" />
                                <div slot="pop">The total order amount refers to the order total calculated by <br> PODpartner, excluding shipping fees and taxes.</div>
                            </UxPopper>
                            <em>USD</em>
                        </h3>
                        <strong v-text="(total_amount / 100).toFixed(2)"></strong>
                    </li>
                </ul>
            </div>

            <div class="distributor-why">
                <h3>Why choose PODpartner Affiliate Program?</h3>
                <ul>
                    <li>
                        <figure><img src="https://img.podpartner.com/static/images-20230328/distributor-choose-1.png" alt=""></figure>
                        <p>Within 12 months from a referred new customer's initial order date</p>
                    </li>
                    <li>
                        <figure><img src="https://img.podpartner.com/static/images-20230328/distributor-choose-2.png" alt=""></figure>
                        <p>Earn a commission of 4% on each sale generated through your affiliate link</p>
                    </li>
                    <li>
                        <figure><img src="https://img.podpartner.com/static/images-20230328/distributor-choose-3.png" alt=""></figure>
                        <p>Commission is paid to your designated PayPal account on a quarterly basis</p>
                    </li>
                </ul>

            </div>
        </div>

    </div>
</template>
<script>
export default {
    name: "distributor",
    layout: "layout-logined",
    data () {
        return {
            loading: false,
            total_amount: 0,
            total_count: 0,
            user_count: 0,
            url: '',
        };
    },
    methods: {
        async getDate () {
            const response = await this.$http('User.distribution');
            if (response.code === 0 && response.data) {
                // 有值
                const data = response.data;
                this.total_amount = data.total_amount || 0;
                this.total_count = data.total_count || 0;
                this.user_count = data.user_count || 0;
                this.url = data.url || '';
                this.loading = false;
            } else {
                this.$router.replace('/user');
            }
        },
        doCopy () {
            var text = this.url;
            if (navigator.clipboard) {
                // clipboard api 复制
                navigator.clipboard.writeText(text);
            } else {
                var textarea = document.createElement('textarea');
                document.body.appendChild(textarea);
                // 隐藏此输入框
                textarea.style.position = 'fixed';
                textarea.style.clip = 'rect(0 0 0 0)';
                textarea.style.top = '10px';
                // 赋值
                textarea.value = text;
                // 选中
                textarea.select();
                // 复制
                document.execCommand('copy', true);
                // 移除输入框
                document.body.removeChild(textarea);
            }

            this.$uxMessage.success('Successfully copied!')
        }
    },
    created () {
        this.getDate();
    },
};
</script>
<style lang="scss" scoped>
.distributor {
    background: #fff;
}

.distributor-body {
    width: 980px;
    margin: 0 auto;
    padding-bottom: 107px;

    & > h2 {
        padding: 60px 0;
        height: 34px;
        font-size: 26px;
        font-family: Roboto-Medium, Roboto;
        font-weight: 500;
        color: #000000;
        line-height: 34px;
    }

    .distributor-link {
        display: flex;
        flex-wrap: wrap;
        h3 {
            width: 100%;
            height: 18px;
            font-size: 16px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #000000;
            line-height: 18px;
        }

        strong {
            margin-top: 20px;
            width: 444px;
            height: 40px;
            line-height: 40px;
            padding: 0 12px;
            box-sizing: border-box;
            background: #f6f6f6;
            border-radius: 6px;
            font-size: 14px;
            font-family: Roboto-Regular, Roboto;
            font-weight: 400;
            color: #555555;
            margin-right: 14px;
        }

        button {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 20px;
            width: 108px;
            height: 40px;
            line-height: 40px;
            background: #ffffff;
            border-radius: 6px;
            border: 1px solid #c6c6c6;
            font-size: 14px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #000000;
            svg {
                width: 16px;
                height: 16px;
                margin-right: 4px;
                color: #555;
            }

            &:hover {
                border-color: #ea4c89;
                color: #ea4c89;
                svg {
                    color: #ea4c89;
                }
            }
        }
        h6 {
            margin-top: 20px;
            height: 14px;
            font-size: 12px;
            font-family: Roboto-Regular, Roboto;
            font-weight: 400;
            color: #000000;
            line-height: 14px;
            display: flex;
            align-items: center;
            svg {
                width: 12px;
                height: 12px;
                font-size: 12px;
                background-color: #ccc;
                color: #fff;
                border-radius: 12px;
                margin-right: 4px;
            }
            span {
                white-space: normal;
            }
        }
    }

    .distributor-statistics {
        position: relative;
        margin-top: 60px;
        &::before {
            content: 'Stats';
            display: block;
            height: 18px;
            font-size: 16px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #000000;
            line-height: 18px;
        }

        ul {
            display: flex;
            width: 100%;
            margin: 18px -7px 0;
        }

        li {
            width: calc(33.3% - 7px);
            margin: 0 7px;
            height: 160px;
            box-sizing: border-box;
            background: #ffffff;
            border-radius: 6px;
            border: 1px solid #e6e6e6;
            padding: 18px 20px;
            display: flex;
            flex-direction: column;
            align-items: flex-start;

            h3 {
                width: 100%;
                height: 16px;
                font-size: 14px;
                font-family: Roboto-Regular, Roboto;
                font-weight: 400;
                color: #555555;
                line-height: 16px;
                display: flex;
                align-items: center;
                position: relative;
                svg {
                    margin-left: 4px;
                    width: 14px;
                    height: 14px;
                    border-radius: 14px;
                    background-color: #b8b8b8;
                    color: #fff;
                }

                em {
                    position: absolute;
                    right: 0;
                    top: 0;
                    width: 32px;
                    height: 16px;
                    background: #f5f5f5;
                    border-radius: 4px;
                    font-size: 12px;
                    font-family: Roboto-Regular, Roboto;
                    font-weight: 400;
                    color: #555555;
                    text-align: center;
                    line-height: 16px;
                }
            }

            strong {
                margin-top: 28px;
                font-size: 40px;
                font-family: Roboto-Medium, Roboto;
                font-weight: 500;
                color: #000000;
                line-height: 40px;
                padding-bottom: 30px;
                position: relative;
                &::after {
                    content: '';
                    position: absolute;
                    left: 0;
                    bottom: 0;
                    width: 100%;
                    height: 4px;
                    background: #3199bd;
                    border-radius: 2px;
                }
            }

            .popper::v-deep {
                width: 14px;
                height: 14px;
                .popper-content {
                    font-size: 12px;
                    background: rgba(0, 0, 0, 0.75);
                    box-shadow: 0px 6px 9px 0px rgba(0, 0, 0, 0.2);
                    border-radius: 5px;
                    padding: 11px 12px;
                    font-size: 12px;
                    font-family: Roboto-Regular, Roboto;
                    font-weight: 400;
                    color: #ffffff;
                    line-height: 16px;
                }
                .arrow {
                    background: none;
                    &::before {
                        top: 4px;
                        transform: rotate(0);
                        background: none;
                        border: none;
                        width: 0;
                        height: 0;
                        border-width: 6px;
                        border-style: solid;
                        border-color: rgba(0, 0, 0, 0.75) transparent
                            transparent transparent;
                    }
                }
            }

            &:nth-child(2) strong::after {
                background-color: #2f9631;
            }

            &:nth-child(3) strong::after {
                background-color: #e7a51a;
            }
        }
    }

    .distributor-why {
        margin-top: 60px;
        h3 {
            height: 18px;
            font-size: 16px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #000000;
            line-height: 18px;
        }

        ul {
            margin: 18px -12px 0;
            display: flex;
        }

        li {
            width: calc(33.3% - 24px);
            margin: 0 12px;
            background: #ffffff;
            border-radius: 4px;
            border: 1px solid #ebebeb;
            box-sizing: border-box;

            figure {
                padding-bottom: 70.32%;
                position: relative;
                img {
                    position: absolute;
                    left: 0;
                    top: 0;
                    width: 100%;
                    height: 100%;
                }
            }

            p {
                padding: 15px 16px;
                font-size: 14px;
                font-family: Roboto-Regular, Roboto;
                font-weight: 400;
                color: #555555;
                line-height: 18px;
            }
        }
    }
}
</style>
